package http

import (
	"embed"
	"io/fs"
	"net/http"
	"path"
)

func EmbedHandler(prefix, dir string, efs embed.FS) (http.Handler, error) {
	web, err := fs.Sub(efs, dir)
	if err != nil {
		return nil, err
	}
	prefix = path.Clean(prefix)
	handler := http.StripPrefix(prefix, http.FileServer(http.FS(web)))
	return handler, nil
}
